{template 'common/header'}
<script  async="true" src="{MODULE_URL}public/sweetalert/sweetalert2.common.js"></script>
<link href="{MODULE_URL}template/web/css/classlist.css" rel="stylesheet" type="text/css">
<div class="mii-box text-center">
    <div class="sobox">
        <input type="text"  name="sokey" class="sokey" placeholder="会员ID/会员手机号/会员姓名/会员编号">        
        <button type="button" class="btn dropdown-toggle submit" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">查询条件 <span class="caret"></span></button>
        <ul class="dropdown-menu dropdown-menu-right">             
          <li><a id="somemberid" data-href="{php echo $this->createWebUrl('somember',array('so'=>'somemberid'));}&key=">会员ID</a></li>
          <li role="separator" class="divider"></li> 
          <li><a id="somembername" data-href="{php echo $this->createWebUrl('somember',array('so'=>'somembername'));}&key=">会员名称</a></li>
         <li role="separator" class="divider"></li> 
          <li><a id="somembermobile" data-href="{php echo $this->createWebUrl('somember',array('so'=>'somembermobile'));}&key=">会员手机号</a></li>          
          <li role="separator" class="divider"></li> 
          <li role="separator" class="divider"></li> 
          <li><a id="somemberon" data-href="{php echo $this->createWebUrl('somember',array('so'=>'somemberon'));}&key=">会员编号</a></li>          
          <li role="separator" class="divider"></li> 
        </ul>
    </div>
</div>
<!-- 搜索框 -->
    <div class="list_th">
        <div class="td" style=" width:10%;">
            <div class="left_padding">会员id</div>
        </div>
        <div class="td" style=" width:15%;">昵称/微信昵称</div>
        <div class="td text-center" style=" width:10%;">会员卡号</div>
        <div class="td text-center" style=" width:10%;">会员余额</div>
        <div class="td text-center" style=" width:10%;">会员消费</div>
        <div class="td text-center" style=" width:10%;">会员等级</div>        
        <div class="td text-center" style=" width:10%;">联系电话</div>
        <div class="td text-center" style=" width:25%;">
            <div class="list_right text-center">操作</div>
        </div>
        <div class="clear"></div>
    </div>
    {if $member}
    {loop $member $k $o}
    <div class="list_tr link_bk">
            <div class="td text-center" style=" width:10%;">
                <div class="category_input left_padding">
                    <span style="color:#999999; margin-left: 5px; font-size: 12px;">{$o['uid']}</span>
                </div>
                <div class="clear"></div>
            </div>
            <div class="td" style=" width:15%; font-size: 12px;" >
              <span style="padding:2px 5px;background: rgb(224,180,59); color: #fff; border-radius: 2px;">{if $o['name']}{$o['name']}{else}未绑定{/if}</span> 
              <span title="{if $o['nickname']}{$o['nickname']}{else}未绑定{/if}" style="padding:2px 5px;background: rgb(97,188,72);color: #fff; border-radius: 2px;">{if $o['nickname']}{$o['nickname']}{else}未绑定{/if}</span>
            </div>      
            <div class="td text-center" style=" width:10%; color: #ff5d38;font-size: 12px;" >
                {if $o['mcard_on']}<span style="padding:2px 5px;background: #7800ff;color: #fff;border-radius: 2px;">{$o['mcard_on']}</span>{else}<span style="padding:2px 5px;background: #999;color: #fff;border-radius: 2px;">未激活</span>{/if}
            </div>
            <div class="td text-center" style=" width:10%; color: #ff5d38;font-size: 12px; font-weight: bold;" >
                {if $o['balance']}{$o['balance']}{else}0.00{/if}
            </div>
            <div class="td text-center" style=" width:10%; color: #ff5d38;font-size: 12px;font-weight: bold;" >
                {if $o['consumption']}{$o['consumption']}{else}0.00{/if}
            </div>
            <div class="td text-center" style=" width:10%;font-size: 12px;" >
                {if $o['activation']==1}<span style="padding:2px 5px;background: rgb(224,180,59);color: #fff; border-radius: 2px;">{php echo memberlevel($o['consumption'])}</span>{else}<span style="padding:2px 5px;background: #999;color: #fff;border-radius: 2px;">普通用户</span>{/if}
            </div>
            <div class="td text-center" style="width:10%; color: #ff5d38;font-size: 12px;" >
                {if $o['phone']}{$o['phone']}{else}{if $o['uPhone']}{$o['uPhone']}{else}未绑定{/if}{/if}
            </div>                                                                                
            <div class="td text-center" style=" width:25%;font-size: 12px;">
                <span class="details" data-uid="{$o['uid']}" style="cursor:pointer;padding:2px 5px;background: rgb(224,180,59);color: #fff; border-radius: 2px;">详情</span>
                <span class="somemberorder" uid="{$o['uid']}"  style="cursor:pointer;padding:2px 5px;background: rgb(224,180,59);color: #fff; border-radius: 2px;">订单</span>
                <span class="m-recharge" data-ac="{if $o['activation']}{$o['activation']}{else}-1{/if}" data-mid={$o['uid']} data-balance="{$o['balance']}" style="cursor:pointer;padding:2px 5px;background: rgb(224,180,59);color: #fff; border-radius: 2px;">充值</span>
                <span class="m-activation" data-ac="{if $o['activation']}{$o['activation']}{else}-1{/if}" data-mid = "{$o['uid']}" style="cursor:pointer;padding:2px 5px;background: rgb(224,180,59);color: #fff; border-radius: 2px;">激活会员</span>
                <span class="delete" did="{$o['uid']}" style="cursor:pointer;padding:2px 5px;background: rgb(224,180,59);color: #fff; border-radius: 2px;">删除</span>
            </div>
            <div class="clear"></div>
        </div>
    {/loop}
    {else}  
    {/if}
<div class="list_tr">  
<div class="text-center" style="margin: 10px 0 0 0;">
  {php echo $pager;}
</div> 
</div>
<style type="text/css">
.btn-danger{margin-left: 10px;}.right-content{padding: 0;}.hot_1{background-color: red;}.hide{display: none;}
.sobox{
    width: 450px;
    height: 70px;
    margin: auto;
    position: relative;
    display: block;
}
    .mii-box{
        width: 98%;
        height: 100px;
        line-height: 100px;
        margin-right: 1%;
        margin-left: 1%;
        background-color: #fff; 
    }
    .soisok{
        width: 100px;
        height: 35px;
        border-radius: 2px;
        border: 1px solid #ff5d38;
        background-image: none;
        box-shadow: 0 0 10px rgba(255,93,56,.6);
        text-align: center;
        outline: none;        
    }
    .soclass{
        width: 100px;   
        height: 35px;
        border-radius: 2px;
        border: 1px solid #ff5d38;
        background-image: none;
        box-shadow: 0 0 10px rgba(255,93,56,.6);
        text-align: center;
        outline: none;        
    }
    .sokey{
        width: 300px;
        height: 35px;
        border-radius: 2px;
        border: 1px solid #ff5d38;
        background-image: none;
        box-shadow: 0 0 10px rgba(255,93,56,.6);
        text-align: center;
        outline: none;
    }

    .submit{
        width: 100px;
        height: 35px;
        background-color: #ff5d38;
        color: #FFFFFF;
        border-radius: 2px;
        border:0;
        display: inline-block;
        padding: 8px 12px;
        box-sizing: border-box;
        box-shadow: 0 2px 2px 0 rgba(255,93,56, 0.14), 0 3px 1px -2px rgba(255,93,56, 0.2), 0 1px 5px 0 rgba(255,93,56, 0.12);    
        line-height: 0px;  
        outline: none;  
    }
    .submit:hover{
        box-shadow: 0 14px 26px -12px rgba(255,93,56, 0.42), 0 4px 23px 0px rgba(0, 0, 0, 0.12), 0 8px 10px -5px rgba(255,93,56, 0.2);
    }
</style>
<link rel="stylesheet" type="text/css" href="{MODULE_URL}public/sweetalert/sweetalert2.min.css"> 
<script src="{MODULE_URL}public/sweetalert/es6-promise.min.js"></script> 
<script src="{MODULE_URL}public/js/Toast.js"></script>
<script src="{MODULE_URL}public/js/mii.common.js"></script>
<link rel="stylesheet" href="{MODULE_URL}public/css/Toast.css">
<script type="text/javascript">
$(document).ready(function(){
        $('.details').on('click',function(){
              var uid = $(this).attr('data-uid');
              var url = "{php echo $this->createWebUrl('memberdetails');}&uid="+uid;
              window.location.href = url;          
        })  
        //激活会员
        $('.m-activation').on('click', function() {
            var ac = $(this).attr('data-ac');
            var mid = $(this).attr('data-mid');
            if(ac != 1 && mid ){
                activation(mid);
            }else{
              swal({
                  text: '已激活,无需再操作',
                  type: 'success',
                  confirmButtonText:'确认',
                  confirmButtonColor:'#7800ff'
              })
            }
          });
        //充值会员卡
        $('.m-recharge').on('click',function(){
            var ac = $(this).attr('data-ac');
            var mid = $(this).attr('data-mid');
            var balance = parseFloat($(this).attr('data-balance')).toFixed(2);
            var url = "{php echo $this->createWebUrl('rechargemcard');}&version_id="+"{$_GPC['version_id']}";
            if(ac == 1 && mid){
              swal({
                title: '请输入充值金额',
                input: 'text',
                showCancelButton: true,
                inputPlaceholder: '0.00',
                confirmButtonColor:'#7800ff',
                confirmButtonText: '充值',
                cancelButtonText:'取消',
                preConfirm: function(money) {
                  return new Promise(function(resolve, reject) {
                    if (isNaN(money) || money =='') {
                      swal.showValidationError('充值金额应为纯数字')
                    } 
                    else if(parseFloat(money).toFixed(2)>20000)
                    {
                      swal.showValidationError('充值金额过大,请分批充值')
                    }
                    else if(parseFloat(money).toFixed(2)<0 && Math.abs(money)>balance)
                    {
                      swal.showValidationError('所扣余额不足,无法进行扣除操作');
                    }
                    else
                    {
                      resolve();
                    }
                  });
                },
                allowOutsideClick: false
              }).then(function(money) {
                if(money){
                    var data = {mid:mid,money:money,validata:1};
                    $.ajax({
                       url:url,
                       data:data,
                       dataType:"json",
                       type:"post",
                       success:function(res){
                          if(res.status==1){
                              swal({
                                  type: 'success',
                                  text: res.msg,
                                  confirmButtonText:'确认',
                                  confirmButtonColor:'#7800ff',
                                  preConfirm: function () {
                                    window.location.reload(); 
                                  }
                              });
                          }else{
                            swal({
                                type: 'error',
                                text: res.msg,
                                confirmButtonText:'确认',
                                confirmButtonColor:'#7800ff',
                            });
                          }
                       },fail:function(res){

                       }
                  });
                }                 
              })
            }else{
              swal({
                title:'请先激活会员',
                text:'会员未激活，不可进行充值操作',
                type:'warning', 
                confirmButtonText:'激活',
                cancelButtonText:'取消',
                confirmButtonColor:'#7800ff', 
                showCancelButton:true,
                preConfirm:function(){
                  activation(mid);
                }                
              })
            }
        })       
        //激活会员end
  $(document).on('click','.delete', function () {
        var did = $(this).attr('did');
        swal({
          title: '确定删除该会员吗？', 
          text: '你将无法恢复删除已会员！', 
          type: 'warning',
          showCancelButton: true, 
          confirmButtonColor:'#7800ff',
          cancelButtonColor: '#d33',
          confirmButtonText: '确定删除！', 
          cancelButtonText: '取消删除！'
        }).then(function(confirm) {
          if(confirm){
           $.ajax({
               url:"{php echo $this->createWebUrl('memberdel');}&version_id="+"{$_GPC['version_id']}",
               data:{did:did},
               dataType:"json",
               type:"post",
              success:function(res){
                 if(res.status== 1){
                     swal({
                        title:res.msg,
                        type:'success',
                        confirmButtonColor:'#7800ff',
                        preConfirm:function()
                        {
                          window.location.reload(); 
                        }
                      });                      
                     return false;
                 }else{
                     swal({
                      title:res.msg,
                      type:'error'
                     })
                     return false;
                 }
              }
            })            
         }
        })             
    });
    // 删除会员end   
     $(document).on('click','.Getopenid',function(){
        var _this = $(this);
        var  uid= _this.attr('uid');
        $.ajax({
           url:"{php echo $this->createWebUrl('getopenid');}&version_id="+"{$_GPC['version_id']}",
           data:{uid:uid},
           dataType:"json",
           type:"post",
          success:function(res){
            if(res.status=='1'){
                mqToast({type:1,context: res.msg})
                 $("#openid_"+uid).val(res.code);
                return false;
            }else{
                mqToast({type:1,context: res.msg})
                return false;
            }
          }
        });
     });
     //搜索会员订单
    $('.somemberorder').on("click",function(){
         var toSearchPage = '{php echo $this->createWebUrl('soorder',array('so'=>'somemberid'));}&key=';
         var key = $.trim($(this).attr('uid'));
         if(key==''){
            mqToast({type:1,context: '请输入要搜索的会员id'});  
            return false
         }else{
            window.location.href = toSearchPage + key;
         }
    }); 
    //激活
    function activation (mid){
      swal({
          title: '激活会员',
          confirmButtonText:'提交',
          showCancelButton:true,
          cancelButtonText:'取消',
          confirmButtonColor:'#7800ff',
          html:'<div class="form-horizontal"><div class="form-group"><label class="col-sm-3 control-label">会员姓名</label><div class="col-sm-8"><input type="text" class="form-control" id="m-name" name="name" value=""></div></div>'+
              '<div class="form-group"><label class="col-sm-3 control-label">会员手机</label><div class="col-sm-8"><input type="text" class="form-control" id="m-phone" name="info" value=""></div></div></div>',
          preConfirm: function () {
            return new Promise(function (resolve) {
              var name = $('#m-name').val();
              var phone = $('#m-phone').val();
              var reg = /^1[3|4|5|7|8][0-9]{9}$/              
              if(name==''){
                  swal.showValidationError('请输入会员姓名') 
                  return false
              }
              if(phone==''){
                  swal.showValidationError('请输入会员手机') 
                  return false
              }
              if(!(reg.test(phone))){
                  swal.showValidationError('请填写正确的会员手机')
                  return false
              }
              resolve([{'name':$('#m-name').val(),'phone':$('#m-phone').val()}])
            })
          },
          onOpen: function () {
            $('#m-name').focus()
          }
        }).then(function (res) {
          if(res){
               $.ajax({
                   url:"{php echo $this->createWebUrl('acmcard');}&version_id="+"{$_GPC['version_id']}",
                   data:{mid:mid,name:res[0]['name'],phone:res[0]['phone']},
                   dataType:"json",
                   type:"post",
                  success:function(res){
                     if(res.status== 1){
                          swal({
                              text: res.msg,
                              type: 'success',
                              confirmButtonText:'确认',
                              confirmButtonColor:'#7800ff',
                              preConfirm: function () {
                                window.location.reload(); 
                              }
                          })                        
                         return false;
                     }else{
                         swal({
                              text: res.msg,
                              type: 'error',
                              confirmButtonText:'确认',
                              confirmButtonColor:'#7800ff',                              
                          })
                         return false;
                     }
                  }
                })          
            }
        }).catch(swal.noop)      
    }
            
});
$('#somemberid').on("click",function(){
         var toSearchPage = $(this).attr('data-href');
         var key = $.trim($('.sokey').val());
         if(key==''){
            mqToast({type:1,context: '请输入要搜索的会员id'});  
            return false
         }else{
            window.location.href = toSearchPage + key;
         }
    })
    $('#somembername').on("click",function(){
         var toSearchPage = $(this).attr('data-href');
         var key = $.trim($('.sokey').val());
         if(key==''){
            mqToast({type:1,context: '请输入要搜索的会员名称'});  
            return false
         }else{
            window.location.href = toSearchPage + key;
         }
    })
    $('#somemberon').on("click",function(){
         var toSearchPage = $(this).attr('data-href');
         var key = $.trim($('.sokey').val());
         if(key==''){
            mqToast({type:1,context: '请输入要搜索的会员编号'});  
            return false
         }else{
            window.location.href = toSearchPage + key;
         }
    })    
    $('#somembermobile').on("click",function(){
         var toSearchPage = $(this).attr('data-href');
         var key = $.trim($('.sokey').val());
         if(key==''){
            mqToast({type:1,context: '请输入要搜索的会员手机号'});  
            return false
         }else{
            window.location.href = toSearchPage + key;
         }
    })       
</script>
{template 'common/footer'}
